<template>
	<el-container>
		<el-header style="height: auto;">
			<sc-select-filter :data="filterData" :label-width="80" @on-change="filterChange"></sc-select-filter>
		</el-header>
		<el-header>
			<div class="left-panel">
				<el-button type="danger" plain icon="el-icon-delete" :disabled="selection.length==0" @click="batch_del"></el-button>
			</div>
			<div class="right-panel">
			</div>
		</el-header>
		<el-main class="nopadding">
			<scTable ref="table" :apiObj="apiObj" row-key="roleId" @selection-change="selectionChange" stripe>
				<el-table-column type="selection" width="50"></el-table-column>
				<el-table-column label="#" type="index" width="50"></el-table-column>
				<el-table-column label="事件标识" prop="eventId" width="300" :show-overflow-tooltip="true"></el-table-column>
				<el-table-column label="操作人" prop="userName" width="150"></el-table-column>
				<el-table-column label="事件序号" prop="eventSeq" width="100"></el-table-column>
				<el-table-column label="记录源值" prop="resValue" min-width="150" :show-overflow-tooltip="true"></el-table-column>
				<el-table-column label="记录最终值" prop="targetValue" min-width="150" :show-overflow-tooltip="true"></el-table-column>
				<el-table-column label="模块名称" prop="moduleTitle" width="100"></el-table-column>
				<el-table-column label="操作类型" prop="optType" width="80"></el-table-column>
				<el-table-column label="操作时间" prop="createTime" width="150"></el-table-column>
				<el-table-column label="事件备注" prop="remark" min-width="150"></el-table-column>
				<el-table-column label="操作" fixed="right" align="right" width="170">
					<template #default="scope">
						<el-button-group>
							<el-button text type="primary" size="small" @click="table_edit(scope.row, scope.$index)" v-if="scope.row.status=='0'">审批</el-button>
							<el-popconfirm title="确定删除吗？" @confirm="table_del(scope.row, scope.$index)">
								<template #reference>
									<el-button text type="primary" size="small">删除</el-button>
								</template>
							</el-popconfirm>
						</el-button-group>
					</template>
				</el-table-column>
			</scTable>
		</el-main>
	</el-container>
	<save-dialog v-if="dialog.save" ref="saveDialog" @success="handleSuccess" @closed="dialog.save=false"></save-dialog>
</template>

<script>
import saveDialog from "./save.vue";

import scSelectFilter from '@/components/scSelectFilter'
export default {
	components: {
		saveDialog,
		scSelectFilter,
	},
	name: 'Three Member Security',
	data() {
		return {
			dialog: {
				save: false
			},
			apiObj: this.$API.system.sysSecurity.getSysSecurityApprovalList,
			selection: [],
			filterData: [
				{
					title: "日期范围",
					key: "date",
					multiple: false,
					options: [
						{
							label: "全部",
							value: ""
						},
						{
							label: "今日",
							value: "1"
						},
						{
							label: "昨日",
							value: "2"
						},
						{
							label: "一周内",
							value: "3"
						},
						{
							label: "一月内",
							value: "4"
						},
						{
							label: "一月前",
							value: "5"
						}
					]
				},
				{
					title: "操作方式",
					key: "optType",
					multiple: false,
					options:[{
						label: "全部",
						value: ""
					},
						{
							label: "添加",
							value: "insert"
						},
						{
							label: "删除",
							value: "delete"
						},
						{
							label: "更新",
							value: "update"
						}
					]
				},
				{
					title: "业务模块",
					key: "module",
					multiple: false,
					options: [{
						value: '',
						label: '全部'
					},{
						value: 'unit',
						label: '单位信息'
					},{
						value: 'userInfo',
						label: '用户信息'
					},{
						value: 'unitDept',
						label: '部门信息'
					},{
						value: 'userRole',
						label: '用户权限'
					},{
						value: 'userLevel',
						label: '行政级别'
					}],
				}
			],
			search: {
				date:'',
				optType: '',
				module:''
			}
		}
	},
	mounted() {
	},
	methods: {
		//表格选择后回调事件
		selectionChange(selection) {
			this.selection = selection;
		},
		filterChange(data){
			this.search.date = data.date;
			this.search.optType = data.optType;
			this.search.module = data.module;
			this.$refs.table.upData(this.search)
		},
		//删除
		async table_del(row) {
			var reqData = {recordId: row.recordId}
			var res = await this.$API.system.sysSecurity.deleteSysSecurityEvent.post(reqData);
			if (res.code == 200) {
				this.$refs.table.refresh()
				this.$message.success("删除成功")
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		async deleteThreeEventRecordByIds(params) {
			const loading = this.$loading();
			var res = await this.$API.system.sysSecurity.deleteSysSecurityEventByIds.post(params);
			if (res.code == 200) {
				this.$refs.table.refresh()
				this.$message.success(res.message)
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
			loading.close();
		},
		//批量删除
		async batch_del() {
			await this.$confirm(`确定删除选中的 ${this.selection.length} 项吗？`, '提示', {
				type: 'warning'
			}).then(() => {
				var recordIdArr = [];
				for (var i = 0; i < this.selection.length; i++) {
					recordIdArr.push(this.selection[i].recordId);
				}
				this.deleteThreeEventRecordByIds({ids: recordIdArr});
			}).catch(() => {

			})
		},
		table_edit(row) {
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open('edit').setData(row)
			})
		},
		handleSuccess(){
			this.$refs.table.refresh();
		},
	}
}
</script>

<style>
</style>
